package com.ruoyi.web.controller.social.examine;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.ExaminePlan;
import com.ruoyi.common.core.domain.entity.ExaminePlanDetail;
import com.ruoyi.common.core.domain.entity.ExamineRecord;
import com.ruoyi.common.core.domain.entity.ExamineRecordDetail;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.mapper.ExaminePlanDetailMapper;
import com.ruoyi.system.mapper.ExaminePlanMapper;
import com.ruoyi.system.mapper.ExamineRecordDetailMapper;
import com.ruoyi.system.mapper.ExamineRecordMapper;
import com.ruoyi.system.service.ExamineRecordDetailService;
import com.ruoyi.system.service.ExamineRecordService;
import com.ruoyi.system.service.resp.ExamineRecordDataDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @Author: ruohao
 * @Date: 2023/9/7
 **/
@RestController
@RequestMapping("/social/examine/recordDetail")
public class ExamineRecordDetailController extends BaseController {
    @Autowired
    private ExamineRecordDetailService examineRecordDetailService;

    @Autowired
    private ExamineRecordService examineRecordService;

    @Resource
    private ExaminePlanMapper examineRecordDetail;

    @Resource
    ExaminePlanDetailMapper examinePlanDetailMapper;

    @Resource
    ExaminePlanMapper examinePlanMapper;

    @Resource
    private ExamineRecordMapper examineRecordMapper;

    @Resource
    private ExamineRecordDetailMapper examineRecordDetailMapper;

    @GetMapping("/lvhuaDatas")
    public AjaxResult lvhuaDatas(ExaminePlan examinePlan) {
        examinePlan.setStatus("启用");
        examinePlan.setType("绿化养护服务");

        //取所有大项
        List<ExamineRecordDataDTO> all = getAllBig(examinePlan);

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
        if (examinePlan.getSearchDate() != null) {
            examinePlan.setSearchKey(dateFormat.format(examinePlan.getSearchDate()));
            if (examinePlan.getSysDateEndTime() == null) {
                examinePlan.setSysDateEndKey(examinePlan.getSearchKey());
            } else {
                examinePlan.setSysDateEndKey(dateFormat.format(examinePlan.getSysDateEndTime()));
            }
        }
        List<ExaminePlan> examinePlans = examineRecordDetail.selectListDetail(examinePlan);
        if (CollectionUtils.isEmpty(examinePlans)) {
            return AjaxResult.success(all);
        }
        List<Long> planIds = examinePlans.stream().map(ExaminePlan::getId).collect(Collectors.toList());
        List<ExamineRecord> examineRecords = examineRecordMapper.selectByPlanIdsAndSearchDate(planIds, examinePlan.getSearchKey(), examinePlan.getSysDateEndKey());
        if (CollectionUtils.isEmpty(examineRecords)) {
            return AjaxResult.success(all);
        }
        List<Long> recordIds = examineRecords.stream().map(ExamineRecord::getId).collect(Collectors.toList());
        List<ExamineRecordDetail> examineRecordDetails = examineRecordDetailMapper.selectByRecordIds(recordIds);
        if (CollectionUtils.isEmpty(examineRecordDetails)) {
            return AjaxResult.success(all);
        }
        Map<String, BigDecimal> result = new HashMap<>();
        for (ExamineRecordDetail detail : examineRecordDetails) {
            BigDecimal total = result.get(detail.getBig());
            if (total == null) {
                result.put(detail.getBig(), Optional.ofNullable(detail.getScore()).orElse(new BigDecimal(0)));
            } else {
                result.put(detail.getBig(), total.add(Optional.ofNullable(detail.getScore()).orElse(new BigDecimal(0))));
            }
        }
        List<ExamineRecordDataDTO> resp = new ArrayList<>();
        for (String big : result.keySet()) {
            ExamineRecordDataDTO examineRecordDataDTO = new ExamineRecordDataDTO();
            examineRecordDataDTO.setBig(big);
            examineRecordDataDTO.setTotal(result.get(big));
            resp.add(examineRecordDataDTO);
        }

        if (CollectionUtils.isEmpty(resp)) {
            return AjaxResult.success(all);
        }

        return AjaxResult.success(resp);
    }

    @GetMapping("/baojieDatas")
    public AjaxResult baojieDatas(ExaminePlan examinePlan) {
        examinePlan.setStatus("启用");
        examinePlan.setType("保洁服务");

        //取所有大项
        List<ExamineRecordDataDTO> all = getAllBig(examinePlan);

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
        if (examinePlan.getSearchDate() != null) {
            examinePlan.setSearchKey(dateFormat.format(examinePlan.getSearchDate()));
            if (examinePlan.getSysDateEndTime() == null) {
                examinePlan.setSysDateEndKey(examinePlan.getSearchKey());
            } else {
                examinePlan.setSysDateEndKey(dateFormat.format(examinePlan.getSysDateEndTime()));
            }
        }
        List<ExaminePlan> examinePlans = examineRecordDetail.selectListDetail(examinePlan);
        if (CollectionUtils.isEmpty(examinePlans)) {
            return AjaxResult.success(all);
        }
        List<Long> planIds = examinePlans.stream().map(ExaminePlan::getId).collect(Collectors.toList());
        List<ExamineRecord> examineRecords = examineRecordMapper.selectByPlanIdsAndSearchDate(planIds, examinePlan.getSearchKey(), examinePlan.getSysDateEndKey());
        if (CollectionUtils.isEmpty(examineRecords)) {
            return AjaxResult.success(all);
        }
        List<Long> recordIds = examineRecords.stream().map(ExamineRecord::getId).collect(Collectors.toList());
        List<ExamineRecordDetail> examineRecordDetails = examineRecordDetailMapper.selectByRecordIds(recordIds);
        if (CollectionUtils.isEmpty(examineRecordDetails)) {
            return AjaxResult.success(all);
        }
        Map<String, BigDecimal> result = new HashMap<>();
        for (ExamineRecordDetail detail : examineRecordDetails) {
            BigDecimal total = result.get(detail.getBig());
            if (total == null) {
                result.put(detail.getBig(), Optional.ofNullable(detail.getScore()).orElse(new BigDecimal(0)));
            } else {
                result.put(detail.getBig(), total.add(Optional.ofNullable(detail.getScore()).orElse(new BigDecimal(0))));
            }
        }
        List<ExamineRecordDataDTO> resp = new ArrayList<>();
        for (String big : result.keySet()) {
            ExamineRecordDataDTO examineRecordDataDTO = new ExamineRecordDataDTO();
            examineRecordDataDTO.setBig(big);
            examineRecordDataDTO.setTotal(result.get(big));
            resp.add(examineRecordDataDTO);
        }

        if (CollectionUtils.isEmpty(resp)) {
            return AjaxResult.success(all);
        }

        return AjaxResult.success(resp);
    }

    @GetMapping("/anbaoDatas")
    public AjaxResult anbaoDatas(ExaminePlan examinePlan) {
        examinePlan.setStatus("启用");
        examinePlan.setType("安保公司");

        //取所有大项
        List<ExamineRecordDataDTO> all = getAllBig(examinePlan);

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
        if (examinePlan.getSearchDate() != null) {
            examinePlan.setSearchKey(dateFormat.format(examinePlan.getSearchDate()));
            if (examinePlan.getSysDateEndTime() == null) {
                examinePlan.setSysDateEndKey(examinePlan.getSearchKey());
            } else {
                examinePlan.setSysDateEndKey(dateFormat.format(examinePlan.getSysDateEndTime()));
            }
        }
        List<ExaminePlan> examinePlans = examineRecordDetail.selectListDetail(examinePlan);
        if (CollectionUtils.isEmpty(examinePlans)) {
            return AjaxResult.success(all);
        }
        List<Long> planIds = examinePlans.stream().map(ExaminePlan::getId).collect(Collectors.toList());
        List<ExamineRecord> examineRecords = examineRecordMapper.selectByPlanIdsAndSearchDate(planIds, examinePlan.getSearchKey(), examinePlan.getSysDateEndKey());
        if (CollectionUtils.isEmpty(examineRecords)) {
            return AjaxResult.success(all);
        }
        List<Long> recordIds = examineRecords.stream().map(ExamineRecord::getId).collect(Collectors.toList());
        List<ExamineRecordDetail> examineRecordDetails = examineRecordDetailMapper.selectByRecordIds(recordIds);
        if (CollectionUtils.isEmpty(examineRecordDetails)) {
            return AjaxResult.success(all);
        }
        Map<String, BigDecimal> result = new HashMap<>();
        for (ExamineRecordDetail detail : examineRecordDetails) {
            BigDecimal total = result.get(detail.getBig());
            if (total == null) {
                result.put(detail.getBig(), Optional.ofNullable(detail.getScore()).orElse(new BigDecimal(0)));
            } else {
                result.put(detail.getBig(), total.add(Optional.ofNullable(detail.getScore()).orElse(new BigDecimal(0))));
            }
        }
        List<ExamineRecordDataDTO> resp = new ArrayList<>();
        for (String big : result.keySet()) {
            ExamineRecordDataDTO examineRecordDataDTO = new ExamineRecordDataDTO();
            examineRecordDataDTO.setBig(big);
            examineRecordDataDTO.setTotal(result.get(big));
            resp.add(examineRecordDataDTO);
        }

        if (CollectionUtils.isEmpty(resp)) {
            return AjaxResult.success(all);
        }
        return AjaxResult.success(resp);
    }

    @GetMapping("/getReportanbao")
    public AjaxResult getReportanbao(ExamineRecordDetail examineRecordDetail) {
        examineRecordDetail.setType("安保公司");
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
        if (examineRecordDetail.getSearchDate() != null) {
            examineRecordDetail.setSearchKey(dateFormat.format(examineRecordDetail.getSearchDate()));
            if (examineRecordDetail.getSysDateEndTime() == null) {
                examineRecordDetail.setSysDateEndKey(examineRecordDetail.getSearchKey());
            } else {
                examineRecordDetail.setSysDateEndKey(dateFormat.format(examineRecordDetail.getSysDateEndTime()));
            }
        }
        List<ExamineRecordDetail> list = examineRecordDetailService.getReportanbao(examineRecordDetail);
        return AjaxResult.success(list);
    }

    @GetMapping("/getReportlvhua")
    public AjaxResult getReportlvhua(ExamineRecordDetail examineRecordDetail) {
        examineRecordDetail.setType("绿化养护服务");
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
        if (examineRecordDetail.getSearchDate() != null) {
            examineRecordDetail.setSearchKey(dateFormat.format(examineRecordDetail.getSearchDate()));
            if (examineRecordDetail.getSysDateEndTime() == null) {
                examineRecordDetail.setSysDateEndKey(examineRecordDetail.getSearchKey());
            } else {
                examineRecordDetail.setSysDateEndKey(dateFormat.format(examineRecordDetail.getSysDateEndTime()));
            }
        }
        List<ExamineRecordDetail> list = examineRecordDetailService.getReportanbao(examineRecordDetail);
        return AjaxResult.success(list);
    }

    @GetMapping("/getReportbaojie")
    public AjaxResult getReportbaojie(ExamineRecordDetail examineRecordDetail) {
        examineRecordDetail.setType("保洁服务");
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
        if (examineRecordDetail.getSearchDate() != null) {
            examineRecordDetail.setSearchKey(dateFormat.format(examineRecordDetail.getSearchDate()));
            if (examineRecordDetail.getSysDateEndTime() == null) {
                examineRecordDetail.setSysDateEndKey(examineRecordDetail.getSearchKey());
            } else {
                examineRecordDetail.setSysDateEndKey(dateFormat.format(examineRecordDetail.getSysDateEndTime()));
            }
        }
        List<ExamineRecordDetail> list = examineRecordDetailService.getReportanbao(examineRecordDetail);
        return AjaxResult.success(list);
    }

    @GetMapping("/lvhuaData")
    public TableDataInfo lvhuaData(ExaminePlan examinePlan) {
        examinePlan.setStatus("启用");
        examinePlan.setType("绿化养护服务");

        //取所有大项
        List<ExamineRecordDataDTO> all = getAllBig(examinePlan);

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
        if (examinePlan.getSearchDate() != null) {
            examinePlan.setSearchKey(dateFormat.format(examinePlan.getSearchDate()));
            if (examinePlan.getSysDateEndTime() == null) {
                examinePlan.setSysDateEndKey(examinePlan.getSearchKey());
            } else {
                examinePlan.setSysDateEndKey(dateFormat.format(examinePlan.getSysDateEndTime()));
            }
        }
        List<ExaminePlan> examinePlans = examineRecordDetail.selectListDetail(examinePlan);
        if (CollectionUtils.isEmpty(examinePlans)) {
            return getDataTable(all);
        }
        List<Long> planIds = examinePlans.stream().map(ExaminePlan::getId).collect(Collectors.toList());
        List<ExamineRecord> examineRecords = examineRecordMapper.selectByPlanIdsAndSearchDate(planIds, examinePlan.getSearchKey(), examinePlan.getSysDateEndKey());
        if (CollectionUtils.isEmpty(examineRecords)) {
            return getDataTable(all);
        }
        List<Long> recordIds = examineRecords.stream().map(ExamineRecord::getId).collect(Collectors.toList());
        List<ExamineRecordDetail> examineRecordDetails = examineRecordDetailMapper.selectByRecordIds(recordIds);
        if (CollectionUtils.isEmpty(examineRecordDetails)) {
            return getDataTable(all);
        }
        Map<String, BigDecimal> result = new HashMap<>();
        for (ExamineRecordDetail detail : examineRecordDetails) {
            BigDecimal total = result.get(detail.getBig());
            if (total == null) {
                result.put(detail.getBig(), Optional.ofNullable(detail.getScore()).orElse(new BigDecimal(0)));
            } else {
                result.put(detail.getBig(), total.add(Optional.ofNullable(detail.getScore()).orElse(new BigDecimal(0))));
            }
        }
        List<ExamineRecordDataDTO> resp = new ArrayList<>();
        for (String big : result.keySet()) {
            ExamineRecordDataDTO examineRecordDataDTO = new ExamineRecordDataDTO();
            examineRecordDataDTO.setBig(big);
            examineRecordDataDTO.setTotal(result.get(big));
            resp.add(examineRecordDataDTO);
        }

        if (CollectionUtils.isEmpty(resp)) {
            return getDataTable(all);
        }

        return getDataTable(resp);
    }

    @GetMapping("/baojieData")
    public TableDataInfo baojieData(ExaminePlan examinePlan) {
        examinePlan.setStatus("启用");
        examinePlan.setType("保洁服务");

        //取所有大项
        List<ExamineRecordDataDTO> all = getAllBig(examinePlan);

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
        if (examinePlan.getSearchDate() != null) {
            examinePlan.setSearchKey(dateFormat.format(examinePlan.getSearchDate()));
            if (examinePlan.getSysDateEndTime() == null) {
                examinePlan.setSysDateEndKey(examinePlan.getSearchKey());
            } else {
                examinePlan.setSysDateEndKey(dateFormat.format(examinePlan.getSysDateEndTime()));
            }
        }
        List<ExaminePlan> examinePlans = examineRecordDetail.selectListDetail(examinePlan);
        if (CollectionUtils.isEmpty(examinePlans)) {
            return getDataTable(all);
        }
        List<Long> planIds = examinePlans.stream().map(ExaminePlan::getId).collect(Collectors.toList());
        List<ExamineRecord> examineRecords = examineRecordMapper.selectByPlanIdsAndSearchDate(planIds, examinePlan.getSearchKey(), examinePlan.getSysDateEndKey());
        if (CollectionUtils.isEmpty(examineRecords)) {
            return getDataTable(all);
        }
        List<Long> recordIds = examineRecords.stream().map(ExamineRecord::getId).collect(Collectors.toList());
        List<ExamineRecordDetail> examineRecordDetails = examineRecordDetailMapper.selectByRecordIds(recordIds);
        if (CollectionUtils.isEmpty(examineRecordDetails)) {
            return getDataTable(all);
        }
        Map<String, BigDecimal> result = new HashMap<>();
        for (ExamineRecordDetail detail : examineRecordDetails) {
            BigDecimal total = result.get(detail.getBig());
            if (total == null) {
                result.put(detail.getBig(), Optional.ofNullable(detail.getScore()).orElse(new BigDecimal(0)));
            } else {
                result.put(detail.getBig(), total.add(Optional.ofNullable(detail.getScore()).orElse(new BigDecimal(0))));
            }
        }
        List<ExamineRecordDataDTO> resp = new ArrayList<>();
        for (String big : result.keySet()) {
            ExamineRecordDataDTO examineRecordDataDTO = new ExamineRecordDataDTO();
            examineRecordDataDTO.setBig(big);
            examineRecordDataDTO.setTotal(result.get(big));
            resp.add(examineRecordDataDTO);
        }

        if (CollectionUtils.isEmpty(resp)) {
            return getDataTable(all);
        }

        return getDataTable(resp);
    }

    private List<ExamineRecordDataDTO> getAllBig(ExaminePlan examinePlan) {
        List<ExamineRecordDataDTO> all = new ArrayList<>();
        //查询最新的考核计划
        Set<String> strings = new HashSet<>();
        List<ExaminePlan> list = examinePlanMapper.selectList(examinePlan);
        if (!CollectionUtils.isEmpty(list)) {
            ExaminePlan examinePlan1 = list.get(0);
            ExaminePlanDetail query = new ExaminePlanDetail();
            query.setPlanId(examinePlan1.getId());
            //获取所有大项
            List<ExaminePlanDetail> details = examinePlanDetailMapper.selectList(query);
            for (ExaminePlanDetail detail : details) {
                strings.add(detail.getBig());
            }

            //直接写死 以后再改 todo
            List<String> res = new ArrayList<>();
            if (examinePlan.getType().equals("绿化养护服务")) {
                res.add("处置应急");
                res.add("其他");
                res.add("绿化养护");
                res.add("管理");
                res.add("人员机械配置标准");
            }
            if (examinePlan.getType().equals("保洁服务")) {
                res.add("处置应急");
                res.add("其他");
                res.add("小区及楼内保洁");
                res.add("管理");
                res.add("人员机械配置标准");
            }
            if (examinePlan.getType().equals("安保公司")) {
                res.add("应急处置");
                res.add("管理");
                res.add("事故");
                res.add("配置标准");
            }

//            if (!CollectionUtils.isEmpty(strings)) {
            if (!CollectionUtils.isEmpty(res)) {
                for (String string : strings) {
                    ExamineRecordDataDTO examineRecordDataDTO = new ExamineRecordDataDTO();
                    examineRecordDataDTO.setBig(string);
                    examineRecordDataDTO.setTotal(BigDecimal.ZERO);
                    all.add(examineRecordDataDTO);
                }
            }
        }
        return all;
    }

    @GetMapping("/anbaoData")
    public TableDataInfo anbaoData(ExaminePlan examinePlan) {
        examinePlan.setStatus("启用");
        examinePlan.setType("安保公司");

        //取所有大项
        List<ExamineRecordDataDTO> all = getAllBig(examinePlan);

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
        if (examinePlan.getSearchDate() != null) {
            examinePlan.setSearchKey(dateFormat.format(examinePlan.getSearchDate()));
            if (examinePlan.getSysDateEndTime() == null) {
                examinePlan.setSysDateEndKey(examinePlan.getSearchKey());
            } else {
                examinePlan.setSysDateEndKey(dateFormat.format(examinePlan.getSysDateEndTime()));
            }
        }
        List<ExaminePlan> examinePlans = examineRecordDetail.selectListDetail(examinePlan);
        if (CollectionUtils.isEmpty(examinePlans)) {
            return getDataTable(all);
        }
        List<Long> planIds = examinePlans.stream().map(ExaminePlan::getId).collect(Collectors.toList());
        List<ExamineRecord> examineRecords = examineRecordMapper.selectByPlanIdsAndSearchDate(planIds, examinePlan.getSearchKey(), examinePlan.getSysDateEndKey());
        if (CollectionUtils.isEmpty(examineRecords)) {
            return getDataTable(all);
        }
        List<Long> recordIds = examineRecords.stream().map(ExamineRecord::getId).collect(Collectors.toList());
        List<ExamineRecordDetail> examineRecordDetails = examineRecordDetailMapper.selectByRecordIds(recordIds);
        if (CollectionUtils.isEmpty(examineRecordDetails)) {
            return getDataTable(all);
        }
        Map<String, BigDecimal> result = new HashMap<>();
        for (ExamineRecordDetail detail : examineRecordDetails) {
            BigDecimal total = result.get(detail.getBig());
            if (total == null) {
                result.put(detail.getBig(), Optional.ofNullable(detail.getScore()).orElse(new BigDecimal(0)));
            } else {
                result.put(detail.getBig(), total.add(Optional.ofNullable(detail.getScore()).orElse(new BigDecimal(0))));
            }
        }
        List<ExamineRecordDataDTO> resp = new ArrayList<>();
        for (String big : result.keySet()) {
            ExamineRecordDataDTO examineRecordDataDTO = new ExamineRecordDataDTO();
            examineRecordDataDTO.setBig(big);
            examineRecordDataDTO.setTotal(result.get(big));
            resp.add(examineRecordDataDTO);
        }

        if (CollectionUtils.isEmpty(resp)) {
            return getDataTable(all);
        }
        return getDataTable(resp);
    }

    @Log(title = "考核方案", businessType = BusinessType.OTHER)
    @GetMapping("/list")
    public TableDataInfo list(ExamineRecordDetail examineRecordDetail) {
        startPage();
        List<ExamineRecordDetail> list = examineRecordDetailService.selectList(examineRecordDetail);
        return getDataTable(list);
    }

    @Log(title = "考核方案All", businessType = BusinessType.OTHER)
    @GetMapping("/listAll")
    public TableDataInfo listAll(ExamineRecordDetail examineRecordDetail) {
        List<ExamineRecordDetail> list = examineRecordDetailService.selectList(examineRecordDetail);
        return getDataTable(list);
    }

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success(examineRecordDetailService.selectById(id));
    }

    @Log(title = "考核方案", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult add(@Validated @RequestBody ExamineRecordDetail examineRecordDetail) {
        examineRecordDetail.setCreateBy(SecurityUtils.getLoginUser().getUser().getNickName());
        Boolean result = examineRecordDetailService.create(examineRecordDetail);

        ExamineRecordDetail search = examineRecordDetailService.selectById(examineRecordDetail.getRecordId());
        if (search == null || !search.getCreateBy().equals(SecurityUtils.getLoginUser().getUser().getNickName())) {
            throw new BaseException("该单据由" + search.getCreateBy() + "创建，您无法修改");
        }

        if (result) {
            return success();
        }
        return error();
    }

    @Log(title = "考核方案", businessType = BusinessType.UPDATE)
    @PutMapping
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult edit(@Validated @RequestBody ExamineRecordDetail examineRecordDetail) {
        examineRecordDetail.setUpdateBy(SecurityUtils.getLoginUser().getUser().getNickName());
        Boolean result = examineRecordDetailService.update(examineRecordDetail);

        ExamineRecordDetail examineRecordDetail1 = examineRecordDetailService.selectById(examineRecordDetail.getId());

        ExamineRecord search = examineRecordService.selectById(examineRecordDetail1.getRecordId());
        if (search == null || !search.getCreateBy().equals(SecurityUtils.getLoginUser().getUser().getNickName())) {
            throw new BaseException("该单据由" + search.getCreateBy() + "创建，您无法修改");
        }

        if (result) {
            return success();
        }
        return error();
    }

    @Log(title = "考核方案", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult remove(@PathVariable Long id) {
        ExamineRecordDetail examineRecordDetail1 = examineRecordDetailService.selectById(id);

        ExamineRecord search = examineRecordService.selectById(examineRecordDetail1.getRecordId());
        if (search == null || !search.getCreateBy().equals(SecurityUtils.getLoginUser().getUser().getNickName())) {
            throw new BaseException("该单据由" + search.getCreateBy() + "创建，您无法修改");
        }
        return toAjax(examineRecordDetailService.deleteById(id));
    }
}
